import 'package:flutter/material.dart';

import '../../../widgets/AppBarWidget.dart';

class VisiblePage extends StatefulWidget {
  const VisiblePage({super.key, required this.valueChanged, required this.initialVisible});

  final num initialVisible;

  final ValueChanged<num> valueChanged;

  @override
  State<VisiblePage> createState() => _VisiblePageState();
}

class _VisiblePageState extends State<VisiblePage> {

  num _selectedIndex=0;


  @override
  void initState() {
    _selectedIndex=widget.initialVisible;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget(title: "谁可见",onConfirmed: (){
        widget.valueChanged.call(_selectedIndex);
      }, context: context,),
      body: Container(
        height: 200,
        color: Colors.white38,
        child: Column(
          children: [
            buildSelectableItem("公开",0),
            buildSelectableItem("仅自己可见",1),
            buildSelectableItem("部分可见",2),
          ],
        ),
      ),
    );
  }

  Widget buildSelectableItem(String title,int curIdx){
    return  Container(
      margin: const EdgeInsets.symmetric(vertical: 5,horizontal: 10),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(5)),
      child: ListTile(
        onTap: () {
          setState(() {
            _selectedIndex=curIdx;
          });
        },
        title: Text(title),
        trailing: _selectedIndex==curIdx ? const Icon(Icons.check_circle,color: Colors.blue,) : null,
      ),
    );
  }
}
